<script>
export default {
  name: 'ScreenTop'
}
</script>
<script setup>
import moment from 'moment'
import { onMounted, onBeforeUnmount, ref } from 'vue'
import { useRouter } from 'vue-router'

const $router = useRouter()

const time = ref(moment().format('YYYY年MM月DD hh:mm:ss'))
let timeoutId
// 在组件挂载时设置定时器
onMounted(() => {
  timeoutId = setInterval(() => {
    time.value = moment().format('YYYY年MM月DD hh:mm:ss')
  }, 1000)
})

// 在组件销毁时清理定时器
onBeforeUnmount(() => {
  clearTimeout(timeoutId)
})

const toRouter = function (routeName) {
  $router.push({ name: routeName })
}
</script>

<template>
  <div class="box">
    <!-- 左边 -->
    <div class="left">
      <div
        class="btn"
        @click="toRouter('Home')"
      >
        <span>首页</span>
      </div>
    </div>

    <!-- 中间 -->
    <div class="center">
      <span class="title">智慧旅游可视化大数据展示平台</span>
      <span class="tip">平台高峰预警信息（2条）</span>
    </div>

    <!-- 右边 -->
    <div class="right">
      <span class="btn">统计报告</span>
      <span class="time">当前时间：{{ time }}</span>
    </div>
  </div>
</template>

<style scoped lang="scss">
.box {
  display: flex;

  @mixin baseBgLayout {
    position: relative;
    width: 30%;
    height: 100%;
  }
  @mixin baseBtnLayout {
    position: absolute;
    width: 25%;
    height: 100%;
    text-align: center;
    line-height: 200%;
    font-size: 19px;
    color: rgb(77, 166, 234);
    background-size: 100% 100%;
    cursor: default;
  }

  .left {
    @include baseBgLayout;
    background: url(../../images/dataScreen-header-left-bg.png) no-repeat;
    background-size: 100% 100%;

    .btn {
      @include baseBtnLayout;
      right: 0;
      background: url(../../images/dataScreen-header-btn-bg-l.png) no-repeat;
      cursor: pointer;
    }
  }

  .center {
    position: relative;
    width: 40%;
    height: 200%;
    background: url(../../images/dataScreen-header-center-bg.png) no-repeat;
    background-size: 100% 100%;

    .title {
      @include baseBtnLayout;
      width: 100%;
      font-size: 35px;
    }
    .tip {
      @include baseBtnLayout;
      width: 100%;
      height: 50%;
      top: 99%;
      color: white;
      font-size: 17px;
      background: url(../../images/dataScreen-header-warn-bg.png) no-repeat;
      background-size: 100% 100%;
    }
  }

  .right {
    @include baseBgLayout;
    background: url(../../images/dataScreen-header-right-bg.png) no-repeat;
    background-size: 100% 100%;

    .btn {
      @include baseBtnLayout;
      left: 0;
      background: url(../../images/dataScreen-header-btn-bg-r.png) no-repeat;
      cursor: pointer;
    }
    .time {
      @include baseBtnLayout;
      width: 75%;
      right: 0;
    }
  }
}
</style>
